package statistics

import (
	"parking-lot-go-admin/controller"
	"parking-lot-go-admin/model"
	"parking-lot-go-admin/model/cars"
	"parking-lot-go-admin/model/order"

	"github.com/gin-gonic/gin"
)

func Grid(c *gin.Context) {

	//今日流水金额
	var carsOutStruct cars.CarsOutStruct
	todayFlowingWater, err := carsOutStruct.TodayFlowingWater()
	if err != nil {
		controller.Fail(c, err.Error())
		return
	}

	//区间流水金额
	sectionFlowingWater, err := carsOutStruct.SectionFlowingWater()
	if err != nil {
		controller.Fail(c, err.Error())
		return
	}

	//今日在场车辆
	var orderStruct order.OrderStruct
	todayInPark, err := orderStruct.TodayInPark()
	if err != nil {
		controller.Fail(c, err.Error())
		return
	}

	//区间在场
	sectionInPark, err := orderStruct.SectionInPark()
	if err != nil {
		controller.Fail(c, err.Error())
		return
	}

	//当前再场车辆
	nowInPark, _ := model.CountModelData(
		model.Db,
		orderStruct.TableName(),
		model.QueryOptions{
			Conditions: map[string]interface{}{
				"status": 1,
			},
		},
	)

	//今日活跃车场
	var CarsEntryStruct cars.CarsEntryStruct
	todayPark := CarsEntryStruct.ActiveParkLot()

	controller.Success(c,
		map[string]interface{}{
			"today_in_park":         todayInPark,
			"section_in_park":       sectionInPark,
			"now_in_park":           nowInPark,
			"today_flowing_water":   todayFlowingWater,
			"section_flowing_water": sectionFlowingWater,
			"today_park":            todayPark,
		})
}
